package com.hxxy.wyp.petsLover.common.rest.base.fronted;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxxy.wyp.petsLover.RestBase;
import com.hxxy.wyp.petsLover.common.entities.UserShare;
import com.hxxy.wyp.petsLover.common.entities.vo.req.SearchObj;
import com.hxxy.wyp.petsLover.common.services.base.backend.UserShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @ClassName UserShareFrontRest
 * @Description TODO
 * @Author wyp
 * @Date 2023/2/11 11:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/userShareFront")
public class UserShareFrontRest extends RestBase {

    @Autowired
    private UserShareService userShareService;


    @RequestMapping("/page")
    @SaCheckLogin
    public Object getUserShareAll(@RequestBody SearchObj searchObj) {

        Page<UserShare> page = userShareService.pageByUserShare(searchObj);
        return ajaxSuccess(page, "200");
    }


    @RequestMapping("/addorJian")
    @SaCheckLogin
    public Object addorJian(@RequestParam("id") String id, @RequestParam("addOrJian") String addOrJian) {
        UserShare userShare = userShareService.getById(id);
        Long shareAlike = userShare.getShareAlike();
        shareAlike = shareAlike + Long.parseLong(addOrJian);
        userShare.setShareAlike(shareAlike);
        boolean b = userShareService.updateById(userShare);
        return ajaxSuccess("200", "操作成功!");
    }

    @RequestMapping("/userShareTheir")
    @SaCheckLogin
    public Object userShareTheir(@RequestBody UserShare userShare) {
        boolean b = userShareService.userShareTheir(userShare);
        if (b) {
            return ajaxSuccess("200", "分享成功!请等待审核~");
        }
        return ajaxSuccess("500", "分享失败！请稍后重试~");
    }

}
